<template>
	<view class="main">

		<view style="padding: 26upx 40upx;">
			<topSelectNew @onSearch="onSearch"></topSelectNew>
		</view>



		<!--list-satrt -->
		<view class="list">
			<view class="item" v-for="item in dataList">
				<image :src="item.cover" class="item-img"></image>
				<view class="item-right">
					<!-- <view class="item-name">这里是名称只有这里是名称只有这里是名称只有一行超出…</view> -->
					<view class="item-name">
						<span class="item-name-left">{{item.name}}</span>
						<span class="item-tag" v-if="item.type ==0">采购</span>
						<span class="item-tag item-tag-red" v-if="item.type ==1">销售</span>
					</view>
					<view class="item-single">单价：¥{{item.unitPrice}}</view>
					<view class="item-total">
						<span>总价：</span>
						<span class="item-total-unit">¥</span>
						<span class="item-total-num">{{item.totalPrice}}</span>
					</view>
					<view class="item-single" v-if="item.createTime">{{item.createTime.substring(0,10)}}</view>
					<view class="item-btn" @click="toDetail(item)" v-if="item.state!= 1">填报</view>
				</view>

				<view class="item-bottom" >
					<span>审核状态：</span>
					<span class="item-bottom-tag item-bottom-yellow" v-if="item.state==0">待填报</span>
					<span class="item-bottom-tag" v-if="item.state==1">通过</span>
					<span class="item-bottom-tag item-bottom-tag-red" v-if="item.state==2">不通过</span>
					<span class="item-bottom-tag item-bottom-tag-red" v-if="item.state==3">待审核</span>
				</view>

			</view>
		</view>
		<!--list-end -->


		<view class="list-end" v-if="dataList.length">{{endText}}</view>

		<u-empty v-if="!dataList.length" mode="car" text="暂无数据" icon="/static/empty-img.png">
		</u-empty>

	</view>
</template>

<script>
	import topSelectNew from './topSelect.vue'
	export default {
		components: {
			topSelectNew
		},
		data() {
			return {
				queryParams: {
					pageNum: 1,
					pageSize: 10
				},
				total: 0,
				endText: '',
				dataList: []

			}
		},
		onLoad() {

		},
		onShow() {
			this.queryParams.pageNum = 1
			this.dataList = []
			this.getList()
		},
		methods: {

			onSearch(param) {
				this.queryParams.pageNum = 1
				this.dataList = []
				this.queryParams = {
					...this.queryParams,
					...param
				}
				this.getList()
			},

			getList() {
				this.$modal.msgLoading('加载中')

				var that = this

				this.$postjson('/api/RqPurchaseOrder/selectOfferByOrder', this.queryParams).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						let detail = res.data.rows
						detail.forEach(v => {
							let img = v.imges ? v.imges.split(',') : []
							if (img.length) {
								v.cover = that.baseUrl + img[0]
							}
						})


						if (detail.length < that.queryParams.pageSize) {
							that.endText = '没有更多了'
						}
						that.total = res.data.total
						that.dataList = that.dataList.concat(detail)
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},



			toDetail(item) {
				// 0-待填报  1-通过  2-不通过  3-待审核
				// 以填报state=0是待填报 ; state=2||state=3是可以修改填报; state=1不可操作
				if(item.state==0){
					uni.navigateTo({
						url: '/pagesMain/purchase/orderFilling/form?rason='+item.rason+'&id='+item.id+'&name='+item.name+'&applicantId='+item.applicantId+'&applicantName='+item.applicantName
					})
				}
				if(item.state==2||item.state==3){
					// uni.navigateTo({
					// 	url: '/pagesMain/purchase/orderFilling/form?rason='+item.rason+'&id='+item.id+'&name='+item.name+'&applicantId='+item.applicantId+'&applicantName='+item.applicantName
					// })
					uni.navigateTo({
						url: '/pagesMain/purchase/orderFilling/form?state='+item.state+'&id='+item.id
					})
				}
				
			},


		},

		onReachBottom: function(e) {
			if (this.total > this.dataList.length) {
				(this.queryParams.pageNum) ++;
				this.getList()
			}
		},
	}
</script>

<style lang="scss" scoped>
	page {
		background: #F9F9F9;
	}

	.main {
		padding: 0;
		padding-bottom: 260upx;
	}

	.list {
		padding: 0 24upx;
		width: calc(100% - 48upx);

		.item {
			margin-bottom: 20upx;
			width: calc(100% - 40upx);
			background: #FFFFFF;
			border-radius: 10upx;
			padding: 20upx;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.item-tag {
				width: 80rpx;
				height: 40rpx;
				background: rgba(17, 170, 102, 0.1);
				border-radius: 4rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #11AB66;
				line-height: 40rpx;
				text-align: center;
				margin-left: 10upx;

			}

			.item-tag-red {
				background: rgba(240, 16, 34, 0.1);
				color: #F01022;
			}

			.item-img {
				width: 170rpx;
				height: 170rpx;
				background: #11AA66;
				border-radius: 8rpx;
			}

			.item-right {
				width: calc(100% - 170upx - 20upx);
				position: relative;

				.item-name {

					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #111111;
					display: flex;
					align-items: center;

					.item-name-left {
						display: inline-block;
						width: calc(100% - 90upx);
						text-overflow: ellipsis;
						overflow: hidden;
						white-space: nowrap;
					}
				}

				.item-single {
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #666666;
					margin-top: 10upx;
				}

				.item-total {
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #666666;
				}

				.item-total-unit {
					font-family: Roboto, Roboto;
					font-weight: 500;
					font-size: 28rpx;
					color: #111111;
				}

				.item-total-num {
					font-family: Roboto, Roboto;
					font-weight: 500;
					font-size: 48rpx;
					color: #111111;
				}

				.item-btn {
					position: absolute;
					width: 142rpx;
					height: 50rpx;
					background: linear-gradient(134deg, #12C66B 0%, #11AA66 100%);
					border-radius: 30rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #FFFFFF;
					line-height: 50upx;
					text-align: center;
					bottom: 28upx;
					right: 0upx;
				}
			}

			.item-bottom {
				flex: 0 0 100%;
				padding-top: 20upx;
				border-top: solid 1rpx rgba(228, 228, 228, 0.6);
				margin-top: 20upx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #666666;

				.item-bottom-tag {
					width: 100rpx;
					height: 40rpx;
					background: #11AA66;
					border-radius: 4rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #FFFFFF;
					line-height: 40upx;
					text-align: center;
					display: inline-block;
				}

				.item-bottom-tag-red {
					background: #F01022;
				}
				.item-bottom-yellow{
					background: #FE9406;
				}
			}
		}

	}

	.tabs {
		// margin-top: 26upx;
		width: 100%;
		height: 106upx;
		display: flex;
		align-items: center;
		z-index: 3;
		position: relative;
		background: #FFFFFF;

		.tabs-item {
			height: 106upx;
			line-height: 106upx;
			text-align: center;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 30rpx;
			color: #999999;
			width: 50%;

		}

		.tabs-item-active {
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 32rpx;
			color: #11AA66;
			position: relative;
			z-index: 4;
		}

		.tabs-item-text {
			position: relative;
			z-index: 4;
		}

		.tabs-item-active::after {
			content: '';
			position: absolute;
			width: 60rpx;
			height: 8rpx;
			background: linear-gradient(180deg, #11AA66 0%, #12C66B 100%);
			bottom: 0upx;
			left: 50%;
			transform: translateX(-50%);
			z-index: 0;
		}

		.tabs-line {
			width: 2upx;
			height: 40upx;
			background: rgba(228, 228, 228, 1);
		}
	}
</style>